<%--
  Created by IntelliJ IDEA.
  User: 王旭东
  Date: 2024/12/14
  Time: 22:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>宠物领养管理后台</title>
    <link href="${pageContext.request.contextPath}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/admin/metisMenu.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/admin/dataTables.bootstrap.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/admin/sb-admin-2.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/admin/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="${pageContext.request.contextPath}/static/css/admin/boot-crm.css" rel="stylesheet" type="text/css">
    <style>
        .panel-heading{background-color: #337ab7;border-color: #2e6da4;font-size:14px;padding-left:20px;height:36px;line-height:36px;color:white;position:relative;cursor:pointer;}/*转成手形图标*/
        .panel-heading span{position:absolute;right:10px;top:12px;}
        table{
            border-bottom: 1px solid #ddd !important;
        }
        .img-avatar {
            width: 50px;
            height: 50px;
            object-fit: cover; /* 保持图片比例，裁剪并填充整个容器 */
            border-radius: 50%; /* 使图片显示为圆形 */
        }
    </style>
</head>
<body>
<div id="wrapper">
    <!-- 导航栏部分 -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <a class="navbar-brand" href="">流浪猫狗管理系统</a>
        </div>
        <!-- 导航栏右侧图标部分 -->
        <!-- 导航栏右侧图标部分 -->
        <ul class="nav navbar-top-links navbar-right">
            <!-- 消息通知 end -->
            <!-- 用户信息和系统设置 start -->
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" href="/admin/developing">
                    <i class="fa fa-user fa-fw"></i>
                    <i class="fa fa-caret-down"></i>
                </a>
                <ul class="dropdown-menu dropdown-user ">
                    <li>
                        <input type="hidden" id = "currentAdminId" value="${admin.id}">
                    </li>
                    <li><a href="/admin/developing"><i class="fa fa-user fa-fw"></i>
                        管理员：${admin.adminName}</a>
                    </li>
                    <li><a href="/admin/developing"><i class="fa fa-gear fa-fw"></i> 系统设置</a></li>
                    <li class="divider"></li>
                    <li>
                        <a href="${pageContext.request.contextPath}/admin/AdminLogin">
                            <i class="fa fa-sign-out fa-fw"></i>退出登录
                        </a>
                    </li>
                </ul>
            </li>
            <!-- 用户信息和系统设置结束 -->
        </ul> <!-- 左侧显示列表部分 start-->
        <div class="navbar-default sidebar" role="navigation">
            <div class="sidebar-nav navbar-collapse">
                <!-- 教学管理  折叠的分组列表 -->
                <div class="panel-heading" id="collapseListGroupHeading3" data-toggle="collapse" data-target="#collapseListGroup3" role="tab">
                    <h4 class="panel-title">
                        后台管理 <span class="fa fa-chevron-up right"></span>
                    </h4>
                </div>
                <div id="collapseListGroup3" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="collapseListGroupHeading3">
                    <ul class="list-group">
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/UserList">
                                <i class="fa fa-flash fa-fw"></i> 用户信息
                            </a>
                        </li>
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/AdminsList">
                                <i class="fa fa-flash fa-fw"></i> 管理员信息
                            </a>
                        </li>
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/PetList">
                                <i class="fa fa-sitemap fa-fw"></i> 宠物管理
                            </a>
                        </li>
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/AdoptList">
                                <i class="fa fa-sitemap fa-fw"></i> 领养管理
                            </a>
                        </li>
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/CommentList">
                                <i class="fa fa-sitemap fa-fw"></i> 评论管理
                            </a>
                        </li>
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/BlogListService">
                                <i class="fa fa-sitemap fa-fw"></i> 团队活动管理
                            </a>
                        </li>
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/ApplyList">
                                <i class="fa fa-sitemap fa-fw"></i> 志愿者申请
                            </a>
                        </li>
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/agreeList">
                                <i class="fa fa-sitemap fa-fw"></i> 同意领养列表
                            </a>
                        </li>
                        <li class="list-group-item my_font">
                            <a href="${pageContext.request.contextPath}/admin/disagreeList">
                                <i class="fa fa-sitemap fa-fw"></i> 不同意领养列表
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </div><!-- 左侧显示列表部分 end-->
    </nav>


    <!-- 管理员信息列表  start-->
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">管理员管理</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="panel panel-default">
            <!-- 搜索部分 -->
            <div class="panel-body">
                <form class="form-inline" method="get" action="${pageContext.request.contextPath}/admin/AdminFingByName">
                    <div class="form-group">
                        <label for="findByName">管理员名称</label>
                        <input type="text" class="form-control" id="findByName" value="" name="realName">
                    </div>
                    <button type="submit" class="btn btn-primary" id="admin_find_modal_btn">查询</button>&nbsp;&nbsp;&nbsp;
                    <input type="button" value="新增" class="btn btn-success" id="admin_add_modal_btn" />
                </form>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">管理员信息列表</div>
                    <!-- /.panel-heading -->
                    <table class="table table-bordered table-striped" id="admin_table">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>管理员账号</th>
                            <th>密码</th>
                            <th>真实姓名</th>
                            <th>电话</th>
                            <th>Email</th>
                            <th>生日</th>
                            <th>性别</th>
                            <th>头像</th>
                            <th>备注</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="admin" items="${admins}">
                            <tr>
                                <td>${admin.id}</td>
                                <td>${admin.adminName}</td>
                                <td>${admin.adminPwd}</td>
                                <td>${admin.realName}</td>
                                <td>${admin.telephone}</td>
                                <td>${admin.email}</td>
                                <td>${admin.birthday}</td>
                                <td>${admin.sex}</td>
                                <td><img class="mySize img-avatar" src="${pageContext.request.contextPath}/static/images/admin/${admin.pic}"/></td>
                                <td>${admin.remark}</td>
                                <td>
                                    <a href="javascript:void(0);" data-toggle="modal" data-target="#adminEditModal" onclick="editAdmin(${admin.id}, '${admin.adminName}', '${admin.adminPwd}', '${admin.realName}', '${admin.telephone}', '${admin.email}', '${admin.birthday}', '${admin.sex}', '${admin.pic}', '${admin.remark}')">
                                        <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>修改
                                    </a>
                                    <a href="javascript:void(0);" onclick="deleteAdmin(${admin.id})">
                                        <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>删除
                                    </a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <div class="col-md-12 text-right">

                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
            <!-- 显示分页信息 -->
            <div class="row">
                <!--分页文字信息  -->
                <div class="col-md-8" id="page_info_area"></div>
                <!-- 分页条信息 -->
                <div class="col-md-4" id="page_nav_area">

                </div>
            </div>
        </div>
    </div>


    <!-- 修改管理员信息的模态框 -->
    <div class="modal fade" id="adminEditModal" tabindex="-1" role="dialog" aria-labelledby="adminEditModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <form id="adminEditForm" action="${pageContext.request.contextPath}/admin/AdminEdit" method="post">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="adminEditModalLabel">修改管理员信息</h4>
                    </div>
                    <div class="modal-body">
                        <input type="hidden" name="id" id="edit_adminId">
                        <div class="form-group">
                            <label for="edit_adminName" class="control-label">管理员账号:</label>
                            <input type="text" class="form-control" id="edit_adminName" name="adminName">
                        </div>
                        <div class="form-group">
                            <label for="edit_adminPwd" class="control-label">密码:</label>
                            <input type="password" class="form-control" id="edit_adminPwd" name="adminPwd">
                        </div>
                        <div class="form-group">
                            <label for="edit_realName" class="control-label">真实姓名:</label>
                            <input type="text" class="form-control" id="edit_realName" name="realName">
                        </div>
                        <div class="form-group">
                            <label for="edit_telephone" class="control-label">电话:</label>
                            <input type="text" class="form-control" id="edit_telephone" name="telephone">
                        </div>
                        <div class="form-group">
                            <label for="edit_email" class="control-label">Email:</label>
                            <input type="email" class="form-control" id="edit_email" name="email">
                        </div>
                        <div class="form-group">
                            <label for="edit_birthday" class="control-label">生日:</label>
                            <input type="date" class="form-control" id="edit_birthday" name="birthday">
                        </div>
                        <div class="form-group">
                            <label for="edit_sex" class="control-label">性别:</label>
                            <select class="form-control" id="edit_sex" name="sex">
                                <option value="男">男</option>
                                <option value="女">女</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="edit_pic" class="control-label">头像:</label>
                            <input type="text" class="form-control" id="edit_pic" name="pic">
                        </div>
                        <div class="form-group">
                            <label for="edit_remark" class="control-label">备注:</label>
                            <textarea class="form-control" id="edit_remark" name="remark"></textarea>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 搜索管理员详细信息模态框 -->
<div class="modal fade" id="adminDetailModal" tabindex="-1" role="dialog" aria-labelledby="adminDetailModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="adminDetailModalLabel">管理员详细信息</h4>
            </div>
            <div class="modal-body">
                <div id="adminDetailContent">
                    <!-- 查询结果将动态填充到这里 -->
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 新增管理员信息的模态框 -->
<div class="modal fade" id="adminAddModal" tabindex="-1" role="dialog" aria-labelledby="adminAddModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form id="adminAddForm" action="${pageContext.request.contextPath}/admin/AdminAdd" method="get">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="adminAddModalLabel">新增管理员信息</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="add_id" class="control-label">编号:</label>
                        <input type="text" class="form-control" id="add_id" name="id">
                    </div>
                    <div class="form-group">
                        <label for="add_adminName" class="control-label">管理员账号:</label>
                        <input type="text" class="form-control" id="add_adminName" name="adminName">
                    </div>
                    <div class="form-group">
                        <label for="add_adminPwd" class="control-label">密码:</label>
                        <input type="password" class="form-control" id="add_adminPwd" name="adminPwd">
                    </div>
                    <div class="form-group">
                        <label for="add_realName" class="control-label">真实姓名:</label>
                        <input type="text" class="form-control" id="add_realName" name="realName">
                    </div>
                    <div class="form-group">
                        <label for="add_telephone" class="control-label">电话:</label>
                        <input type="text" class="form-control" id="add_telephone" name="telephone">
                    </div>
                    <div class="form-group">
                        <label for="add_email" class="control-label">Email:</label>
                        <input type="email" class="form-control" id="add_email" name="email">
                    </div>
                    <div class="form-group">
                        <label for="add_birthday" class="control-label">生日:</label>
                        <input type="date" class="form-control" id="add_birthday" name="birthday">
                    </div>
                    <div class="form-group">
                        <label for="add_sex" class="control-label">性别:</label>
                        <select class="form-control" id="add_sex" name="sex">
                            <option value="男">男</option>
                            <option value="女">女</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="add_pic" class="control-label">头像:</label>
                        <input type="text" class="form-control" id="add_pic" name="pic">
                    </div>
                    <div class="form-group">
                        <label for="add_remark" class="control-label">备注:</label>
                        <textarea class="form-control" id="add_remark" name="remark"></textarea>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>


<!-- 引入js文件 -->
<!-- jQuery -->
<script src="${pageContext.request.contextPath}/static/js/jquery-3.4.1.min.js"></script>
<script src="${pageContext.request.contextPath}/static/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/admin/metisMenu.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/admin/jquery.dataTables.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/admin/dataTables.bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/admin/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script>
<%-- 修改函数--%>
    function editAdmin(id, adminName, adminPwd, realName, telephone, email, birthday, sex, pic, remark) {
        document.getElementById('edit_adminId').value = id;
        document.getElementById('edit_adminName').value = adminName;
        document.getElementById('edit_adminPwd').value = adminPwd;
        document.getElementById('edit_realName').value = realName;
        document.getElementById('edit_telephone').value = telephone;
        document.getElementById('edit_email').value = email;
        document.getElementById('edit_birthday').value = birthday;
        document.getElementById('edit_sex').value = sex;
        document.getElementById('edit_pic').value = pic;
        document.getElementById('edit_remark').value = remark;
    }
// 删除函数
function deleteAdmin(id) {
    if (confirm("确定要删除该管理员吗？")) {
        var form = document.createElement("form");
        form.method = "POST";
        form.action = "${pageContext.request.contextPath}/admin/AdminDelete";

        var hiddenField = document.createElement("input");
        hiddenField.type = "hidden";
        hiddenField.name = "id";
        hiddenField.value = id;
        form.appendChild(hiddenField);

        document.body.appendChild(form);
        form.submit();
    }
}
// 查找函数
$(document).ready(function() {
    $('#admin_find_modal_btn').click(function(event) {
        event.preventDefault(); // 阻止表单默认提交行为
        var realName = $('#findByName').val();
        $.ajax({
            url: "${pageContext.request.contextPath}/admin/AdminFingByName",
            type: "GET",
            data: { realName: realName },
            dataType: "json", // 指定期望的响应数据类型为 JSON
            success: function(admins) {
                if (admins.length > 0) {
                    // 清空模态框内容
                    $('#adminDetailContent').empty();

                    // 遍历返回的管理员列表并动态添加内容
                    $.each(admins, function(index, admin) {
                        var content = '<p><strong>编号：</strong>' + admin.id + '</p>' +
                            '<p><strong>管理员账号：</strong>' + admin.adminName + '</p>' +
                            '<p><strong>密码：</strong>' + admin.adminPwd + '</p>' +
                            '<p><strong>真实姓名：</strong>' + admin.realName + '</p>' +
                            '<p><strong>电话：</strong>' + admin.telephone + '</p>' +
                            '<p><strong>Email：</strong>' + admin.email + '</p>' +
                            '<p><strong>生日：</strong>' + admin.birthday + '</p>' +
                            '<p><strong>性别：</strong>' + admin.sex + '</p>' +
                            '<p><strong>头像：</strong>' + admin.pic+ '</p>' +
                            '<p><strong>备注：</strong>' + admin.remark + '</p>' +
                            '<hr>';
                        $('#adminDetailContent').append(content);
                    });
                    // 显示模态框
                    $('#adminDetailModal').modal('show');
                } else {
                    alert("没有找到匹配的管理员信息");
                }
            },
            error: function() {
                alert("查询失败");
            }
        });
    });
});
// 添加管理员
$(document).ready(function() {
    $('#admin_add_modal_btn').click(function() {
        $('#adminAddModal').modal('show');
    });
});


</script>
</body>
</html>
